﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace FairFare
{
    public partial class Taxi : PhoneApplicationPage
    {
        double dist = 0.0;
        double rem = 0.0;
        double Meru_fare = 0.0;
        double Quick_fare = 0.0;
        double Easy_fare = 0.0;
        double universal_fare = 0.0;

        public Taxi()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string data1 = NavigationContext.QueryString["name"];
            distanceBox.Text = data1;

        }

        private void AutoTab_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Auto.xaml", UriKind.Relative));
        }

        private void TaxiTab_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Taxi.xaml", UriKind.Relative));
        }

        private void MetroTab_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Metro.xaml", UriKind.Relative));
        }

        private void TaxiInfo_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Taxiinfo.xaml", UriKind.Relative));
        }

        private void distanceBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (distanceBox.Text.Trim().Length == 0)
            {
                dist = 0.0;
            }

            else
            {
                dist = float.Parse(distanceBox.Text);
            }


            if (dist <= 0.0)
            {
                universal_fare = 0.0;
                MeruCab_Fare.Text = Convert.ToString(universal_fare);
                QuickCab_Fare.Text = Convert.ToString(universal_fare);
                EasyCab_Fare.Text = Convert.ToString(universal_fare);
            }

            if (dist > 0.0 && dist<=1.0)
            {
                //Meru Cabs
                Meru_fare = 20.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    Meru_fare = Meru_fare + (Meru_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                MeruCab_Fare.Text = Convert.ToString(Meru_fare);


                //Quick Cabs
                Quick_fare = 10.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    Quick_fare = Quick_fare + (Quick_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                QuickCab_Fare.Text = Convert.ToString(Quick_fare);



                //Easy Cabs
                Easy_fare = 20.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    Easy_fare = Easy_fare + (Easy_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                EasyCab_Fare.Text = Convert.ToString(Easy_fare);

            }


            if (dist > 1.0)
            {
                rem = dist - 1.0;
                //Meru Cabs
                Meru_fare = 20.0 + rem*20.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    Meru_fare = Meru_fare + (Meru_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                MeruCab_Fare.Text = Convert.ToString(Meru_fare);


                //Quick Cabs
                Quick_fare = 10.0 + rem * 20.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    Quick_fare = Quick_fare + (Quick_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                QuickCab_Fare.Text = Convert.ToString(Quick_fare);



                //Easy Cabs
                Easy_fare = 20.0 + rem * 20.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    Easy_fare = Easy_fare + (Easy_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                EasyCab_Fare.Text = Convert.ToString(Easy_fare);

            }

           
        }

        

        
    }
}